﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
using B.S.DataBase.EFCoreServiers.IServices.Meetings;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.ErrorCode.ErrorCodes;
using B.S.DataBase.EFCoreServiers.Dtos.MeetingReservations;

namespace B.S.BaseData.ReadAPI.Controllers
{
    /// <summary>
    /// 会议室预约管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    [ApiExplorerSettings(GroupName = "MeetingReservation")]
    public class MeetingReservationController : ControllerBase
    {
        private readonly IMeetingReservationServices _reservationServices;
        private readonly ILogger<MeetingReservationController> _logger;

        /// <summary>
        /// 构造函数
        /// </summary>
        public MeetingReservationController(
            IMeetingReservationServices reservationServices,
            ILogger<MeetingReservationController> logger)
        {
            _reservationServices = reservationServices;
            _logger = logger;
        }

      

        /// <summary>
        /// 获取会议室预约列表
        /// </summary>
        /// <param name="queryDto">查询条件</param>
        /// <returns>预约列表</returns>
        [HttpGet]
        public async Task<ApiResult<ApiPaging<GetMeetingReservationResponseDto>>> GetReservationList([FromQuery] GetMeetingReservationDto queryDto)
        {
            try
            {
                return await _reservationServices.GetReservationListAsync(queryDto);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "获取会议室预约列表失败");
                return ApiResult<ApiPaging<GetMeetingReservationResponseDto>>.Fail(
                    "获取预约列表失败：" + ex.Message,
                    StatusCodeEnum.Exception
                );
            }
        }



    }
}
